package com.company.OfferGuide;

public class 把数组排成最小的数 {

    public String minNumber(int[] nums) {
        if (nums == null || nums.length == 0) return "";
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                long num01 = Long.valueOf(nums[i] + "" + nums[j]);
                long num02 = Long.valueOf(nums[j] + "" + nums[i]);
                if (num01 > num02) {
                    int temp = nums[i];
                    nums[i] = nums[j];
                    nums[j] = temp;
                }

            }
        }

        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < nums.length; i++) {
            sb.append(nums[i]);
        }

        return sb.toString();
    }

}
